package com.sz.sjtb.web;

import com.alibaba.fastjson.JSONObject;
import com.sz.sjtb.domain.User;
import com.sz.sjtb.service.UserService;
import org.apache.log4j.Logger;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping(value = "/users")
public class UserController {
    private Logger logger = Logger.getLogger(getClass());
    @Resource
    private UserService userService;
    @RequestMapping(value = "/getUser", method = RequestMethod.GET)
    public User getUser() {
        User u = new User();
        u.setId(1);
        u.setName("1");
        u.setAge(1);
        logger.info("user="+JSONObject.toJSONString(u));
        return u;
    }
    @RequestMapping(value = "/getUserCount", method = RequestMethod.GET)
    public Integer getUserCount() {

        return userService.getUserCount();
    }
    @RequestMapping(value = "/getAllUsers", method = RequestMethod.GET)
    public List<User> getAllUsers() {
        List<User> list = userService.getAllUsers();
        list.stream().forEach(vo->{
            logger.info(vo.getId());
        });
        return list;
    }
}
